CC ?= gcc
CXX ?= g++
LEX = flex
CURDIR ?= ${.CURDIR}
BUILDDIR = ${CURDIR}/../.build

CFLAGS = 
#CFLAGS += -DDEBUG=1
CFLAGS += -std=c99
CFLAGS += -I${BUILDDIR}/include -I/usr/local/include -I/usr/include 

LDFLAGS += -L${BUILDDIR}/lib -L/usr/local/lib -L/usr/lib64 -L/usr/lib -L/lib64 -L/lib
LDFLAGS += -lreadline
LDFLAGS += -lssl -lcrypto -lz -lcurl -lm -lstdc++ -export-dynamic
#LDFLAGS += -lexecinfo

SOURCES  = js.c   functions.c error.c  eval.c  main.c  thread.c
HEADERS  = js.h   functions.h error.h  eval.h  main.h  thread.h
OTHERS   = jspp.l url.l   config.h  unescape.l filemime.l

MODULES_SRCS = 
MODULES_SRCS += classes/test.c
MODULES_SRCS += classes/server.c
#MODULES_SRCS += classes/http.c
MODULES_SRCS += classes/global.c
MODULES_SRCS += classes/stream.c
MODULES_SRCS += classes/curl.c

MODULES_HDRS = classes/classes.h

LEX_OBJS = jspp.o url.o unescape.o filemime.o

ALL_DEPENDS = ${LEX_OBJS} ${SOURCES} ${MODULES_SRCS} ${MODULES_HDRS} ${HEADERS} ${OTHERS}

all: jsrun
	cp $? ..; cp $? ${HOME}/bin

jsrun: ${ALL_DEPENDS} Makefile
	( \
		PATH=${BUILDDIR}/bin:$$PATH; \
		${CC} -c ${CFLAGS} -I${BUILDDIR}/include `nspr-config --cflags` ${SOURCES} ${MODULES_SRCS} && \
		${CC} -o $@ *.o ${LDFLAGS} `nspr-config --libs` ${BUILDDIR}/lib/libjs_static.a \
	)


#		${CC} -o $@ *.o ${LDFLAGS} `nspr-config --libs` -ljs_static \


dyncall js:
	cd contrib && ${MAKE} $@

clean:
	( find . -type f -name "*.o" -delete;  rm -f *.o jsrun; )

distclean: clean
	rm -rf ./.build jsrun






